module.exports = {
    /**get 请求
     * @param {Object} url
     * @param {Object} data
     * @param {Object} successFun
     * @param {Object} failFun
     * @param {Object} completeFun
     */
    get(url, data, successFun, failFun, completeFun){
        let apiUrl = getApp().globalData.apiUrl,apifrom=false;
        // #ifdef MP-WEIXIN
        apifrom='wxapp';
        // #endif
        
        uni.request({
            url: apiUrl+url,
            data: data,
            method: 'GET',
            header: {'content-type':'application/json','author':'dcr163','apifrom':apifrom},
            success: (res) => {
                successFun && successFun(res);
            },
            fail: (error) => {
                failFun && failFun(error);
            },
            complete: (res) => {
                completeFun && completeFun(res)
            }
        })
    },
    /**
     * post 请求
     * @param {Object} url
     * @param {Object} data
     * @param {Object} successFun
     * @param {Object} failFun
     * @param {Object} completeFun
     */
    post(url, data, successFun, failFun, completeFun) {
        let apiUrl = getApp().globalData.apiUrl,apifrom=false;
        // #ifdef MP-WEIXIN
        apifrom='wxapp';
        // #endif
        uni.request({
            url: apiUrl+url,
            data: data,
            method: 'POST',
            dataType:'JSON',
            header: { 'content-type': 'application/x-www-form-urlencoded','author':'dcr163','apifrom':apifrom},
            success: (res) => {
                successFun && successFun(res);
            },
            fail: (error) => {
                failFun && failFun(error);
            },
            complete: (res) => {
                completeFun && completeFun(res)
            }
        })
    },
    /**
     * 显示成功提示框
     */
    showSuccess(msg, callback) {
        uni.showModal({
            title: '温馨提示',
            content: msg,
            duration: 1500,
            showCancel:false,
            success(res) {
                if (res.confirm) {
                   callback && callback();
                } 
            }
        });
    },
    /**
     * 显示失败提示框
     */
    showError(msg, callback) {
        wx.showModal({
            title: '友情提示',
            content: msg,
            showCancel: false,
            success(res) {
                if (res.confirm) {
                   callback && callback();
                } 
            }
        });
    },

}
